package com.stock.demo.function.home.view;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.stock.demo.R;
import com.stock.demo.framework.ui.activity.BaseNetActivity;

/**
 * Created by xuzhaoyu on 17-7-31.
 */

public class LiveBroadcastDetailActivity extends BaseNetActivity implements LiveBroadcastDetailView {

    private TextView mTvIntroduce;
    private TextView mTvChapter;
    private TextView mTvDiscuss;
    private LiveBroadcastIntroduceFragment mLiveBroadcastIntroduceFragment;
    private LiveBroadcastChapterFragment mLiveBroadcastChapterFragment;
    private LiveBroadcastDiscussFragment mLiveBroadcastDiscussFragment;
    private int mCurrentIndex;

    public static void startAction(Context context) {
        Intent intent = new Intent(context, LiveBroadcastDetailActivity.class);
        context.startActivity(intent);
    }

    @Override
    public void initView() {
        findViewById(R.id.iv_course_detail_finish).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTvIntroduce = (TextView) findViewById(R.id.tv_live_broadcast_detail_introduce);
        mTvChapter = (TextView) findViewById(R.id.tv_live_broadcast_detail_chapter);
        mTvDiscuss = (TextView) findViewById(R.id.tv_live_broadcast_detail_discuss);
        mTvIntroduce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCurrentIndex = 0;
                changePage();
            }
        });
        mTvChapter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCurrentIndex = 1;
                changePage();
            }
        });
        mTvDiscuss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCurrentIndex = 2;
                changePage();
            }
        });
    }

    private void changePage() {
        mTvIntroduce.setBackgroundColor(getResources().getColor(R.color.transparent));
        mTvIntroduce.setTextColor(getResources().getColor(R.color.colorPrimary));
        mTvChapter.setBackgroundColor(getResources().getColor(R.color.transparent));
        mTvChapter.setTextColor(getResources().getColor(R.color.colorPrimary));
        mTvDiscuss.setBackgroundColor(getResources().getColor(R.color.transparent));
        mTvDiscuss.setTextColor(getResources().getColor(R.color.colorPrimary));
        FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction()
                .hide(mLiveBroadcastIntroduceFragment)
                .hide(mLiveBroadcastChapterFragment)
                .hide(mLiveBroadcastDiscussFragment);
        if (mCurrentIndex == 0) {
            mTvIntroduce.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
            mTvIntroduce.setTextColor(getResources().getColor(R.color.colorWhite));
            transaction.show(mLiveBroadcastIntroduceFragment);
        } else if (mCurrentIndex == 1) {
            mTvChapter.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
            mTvChapter.setTextColor(getResources().getColor(R.color.colorWhite));
            transaction.show(mLiveBroadcastChapterFragment);
        } else if (mCurrentIndex == 2) {
            mTvDiscuss.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
            mTvDiscuss.setTextColor(getResources().getColor(R.color.colorWhite));
            transaction.show(mLiveBroadcastDiscussFragment);
        }
        transaction.commit();
    }

    @Override
    public void initData() {
        onNetNext(new Object()).setNetComplete();
        mLiveBroadcastIntroduceFragment = new LiveBroadcastIntroduceFragment();
        mLiveBroadcastChapterFragment = new LiveBroadcastChapterFragment();
        mLiveBroadcastDiscussFragment = new LiveBroadcastDiscussFragment();
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.fl_live_broadcast_detail_fragment_container, mLiveBroadcastIntroduceFragment)
                .add(R.id.fl_live_broadcast_detail_fragment_container, mLiveBroadcastChapterFragment)
                .add(R.id.fl_live_broadcast_detail_fragment_container, mLiveBroadcastDiscussFragment)
                .hide(mLiveBroadcastChapterFragment)
                .hide(mLiveBroadcastDiscussFragment)
                .show(mLiveBroadcastIntroduceFragment)
                .commit();
    }

    @Override
    public View onCreateSuccessView() {
        return LayoutInflater.from(this).inflate(R.layout.activity_live_broadcast_detail, null);
    }

    @Override
    public void onReload(View v) {

    }
}
